import httpClient from "@/lib/http-client";
import memoize from "memoize";


export const memoizedKplTopPlates = memoize(async (num: number = 5) => await fetchTopPlates(num), {maxAge: 5000});
export const memoizedKplTopHys = memoize(async (num: number = 5) => await fetchTopHys(num), {maxAge: 5000});
export const memoizedKplTopMix = memoize(async (num: number = 5) => {
    const {list: hys} = await fetchTopHys(num)
    const {list: plates} = await fetchTopPlates(num)
    return {list: [...hys, ...plates]}
}, {maxAge: 3500})

async function fetchTopPlates(num: number) {
    // console.log('new fetchTopPlates');
    const url = `https://apphq.longhuvip.com/w1/api/index.php?Index=0&Order=1&PhoneOSNew=2&Type=1&VerSion=5.7.0.15&ZSType=7&a=RealRankingInfo&apiv=w31&c=ZhiShuRanking&st=${num}`;
    return await httpClient.get(url) || [];
}

async function fetchTopHys(num: number) {
    const url = `https://apphq.longhuvip.com/w1/api/index.php?Index=0&Order=1&PhoneOSNew=2&Type=1&VerSion=5.7.0.15&ZSType=4&a=RealRankingInfo&apiv=w31&c=ZhiShuRanking&st=${num}`;
    return await httpClient.get(url) || [];
}

async function getKplMix() {

}

async function getTopPlates() {

}

async function getTopHys() {

}